/***************************************************************************
 *   Copyright (C) 2007 by Eduardo Robles Elvira   *
 *   edulix@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef KONNTRACKITEM_H
#define KONNTRACKITEM_H

#include <QString>
#include <QHash>
#include <QHostInfo>
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
#include "common.h"

/**
 * A KonntrackItem contains information related to a specific connection or event.
 * It contains a pointer to the connection (*ct) and an array of data related to it,
 * and those protected members can be accessed via some accessors and mutattors.
 */
class KonntrackItem : public QObject
{
	Q_OBJECT
	public:
		KonntrackItem();
		virtual ~KonntrackItem();
		void setData(KonntrackCol col, QString data);
		QString& getData(int col, bool translated = true);
		nf_conntrack* getConntrack();
		void setConntrack(nf_conntrack *ct);
		int removeConntrack(struct nfct_handle *h);
		
		/**
		 * This function helps sorting by column. A column is sorted in different ways
		 * depending of its type.
		 * @param col Column in question
		 * @return STRING ("google.es"), INT ("456"), or IP ("1.34.56.79")
		 */
		ColumnType columnType(KonntrackCol col);
	
	public slots:
		void lookedUp(QHostInfo hi);
	
	signals:
		void ipNameResolved();
	
	protected:
		nf_conntrack *ct;
		QString data[21];
		static QHash<QString, QString> lookUpTable;
		KonntrackCol lookupCol;
		QObject *parent;
		static uint count;
};

#endif
